<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="./layui/css/layui.css">
</head>
<style>
    .mxnW{
        width: 80%;
        margin: 0 auto;
        margin-top: 20px;
    }
    .hidden{
        display: none;
    }
    select{
        width: 100%;
        height: 38px;
        line-height: 38px;
        line-height: 36px\9;
        border: 1px solid #e6e6e6;
        background-color: #fff;
        border-radius: 2px;
    }
</style>

<body>
<form class="layui-form mxnW" action="" >
    <div class="layui-form-item">
        <label class="layui-form-label">团队</label>
        <div class="layui-input-block" >
            <select name="teamid" id="teamToSelect" lay-ignore onchange="change()"  lay-search lay-verify="required">
                <option value=""></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">项目</label>
        <div class="layui-input-block">
            <select name="projectid"  id="projectSelect" lay-ignore  lay-verify="required">
                <option value=""></option>
            </select>
            <button style="margin-top: 10px" class="layui-btn" onclick="selectIn()">选定</button>
        </div>
    </div>
    <hr>
</form>
<!--//添加团队-->
<button style="margin-top: 50px;margin-left: 70px" onclick="addTeam()" class="layui-btn">创建团队</button>
<!--//创建项目-->
<button style="margin-top: 50px;margin-left: 70px" onclick="addProject()" class="layui-btn">创建项目</button>
<script src="../../public/js/jquery.min.js"></script>
<script>
    $.ajax({
        type: 'POST',
        url:"/team/search",
        data: {data:{key:'userid',value:JSON.parse(sessionStorage.user).userid}},
        success:function (data) {
            console.log(data)
            for(var i=0;i<data.result.length;i++){
                $("#teamToSelect").append(
                    '<option value='+data.result[i].teamid+'>'+data.result[i].title+'</option>'
                )
            }
        } ,
        error:function () {
            layer.msg("系统错误")
        }
    })
    if(sessionStorage.hasOwnProperty("team")){
        $.ajax({
            type: 'POST',
            url:"/project/search",
            data: {data:{key:'teamid',value:JSON.parse(sessionStorage.team).teamid}},
            success:function (data) {
                console.log(data)
                for(var i=0;i<data.result.length;i++){
                    $("#projectSelect").append(
                        '<option value='+data.result[i].projectid+'>'+data.result[i].title+'</option>'
                    )
                }
            } ,
            error:function () {
                layer.msg("系统错误")
            }
        })
    }

</script>
<script src="./layui/layui.js"></script>
<script>
    //Demo
    var tpl={
        data:{},
        setData:function () {
            $("#setImg").attr("src",this.data.picture||"");
            $("input[name='title']").val(this.data.title||"");
            $("textarea[name='abstract']").val(this.data.abstract||"");
        },
        getData:function () {
            return {
            }
        }
    }
    layui.use('form', function(tpl){
        form.on('submit(formDemo)', function(data){

        });
    })
    layui.use('upload', function(){
        layui.upload({
            url: '/ueditor/ue?action=uploadimage'
            ,success: function(res){
                console.log(res); //上传成功返回值，必须为json格式
                if(res.state=="SUCCESS"){
                    layer.msg('上传成功')
                    $("#setImg").attr("src",location.origin+res.url)
                }else{
                    layer.msg('上传失败')
                }
            }
        });
    });
    function addTeam() {
        layer.open({
            type: 2,
            title: '选择设置团队',
            shadeClose: true,
            shade: 1,
            area: ['70%', '90%'],
            content: location.origin+"/webpack/src/pages/layer/setTeam.html",
            end:function () {
                window.location.reload()
            }
        });
    }
    function addProject() {
        layer.open({
            type: 2,
            title: '选择设置团队',
            shadeClose: true,
            shade: 1,
            area: ['70%', '90%'],
            content: location.origin+"/webpack/src/pages/layer/setProject.html",
            end:function () {
                window.location.reload()
            }
        });
    }

    function change() {
        $.ajax({
            type: 'POST',
            url:"/project/search",
            data: {data:{key:'teamid',value:$("#teamToSelect").val()}},
            success:function (data) {
                console.log(data)
                $("#projectSelect").empty();
                for(var i=0;i<data.result.length;i++){
                    $("#projectSelect").append(
                        '<option value='+data.result[i].teamid+'>'+data.result[i].title+'</option>'
                    )
                }
            } ,
            error:function () {
                layer.msg("系统错误")
            }
        })
    }
    function selectIn() {
        alert("选定成功")
        var team=$("#teamToSelect").val(),
            project=$("#projectSelect").val();
        sessionStorage.setItem("myNewProject",JSON.stringify({teamid:team,projectid:project}))
    }
</script>
</body>
</html>